﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Text;
using kim.Common;

namespace kim.UsersControls
{
    public partial class top : System.Web.UI.UserControl
    {
        protected string ImgUrl,strTet;
        public string[] ClassText;
        private int fid;
        protected void Page_Load(object sender, EventArgs e)
        {
            BLL.siteconfig bll = new BLL.siteconfig();
            Model.siteconfig model = bll.loadConfig(Utils.GetXmlMapPath(KIMKeys.FILE_SITE_XML_CONFING));
            ImgUrl = model.Logo;
            strTet = model.webtel;
            GetClass();
        }

        public  string GetSlide(int top, int typeid, int channelID)
        {
            string strSlide = string.Empty;
            List<Model.Show> slide = new BLL.Show().GetModelList(top, "typeid=" + typeid + " and ChannelID=" + channelID + "", "sort asc");
            if (slide.Count > 0)
            {
                foreach (Model.Show mo in slide)
                {
                    strSlide += "<li><a href=\"#\"><img src=\"" + mo.Pic + "\" /></a></li>";
                }
            }
            return strSlide;
        }

        public StringBuilder GetNewList(int classid)
        {
            StringBuilder SlideText = new StringBuilder();
            List<Model.eg_news> slide = new BLL.eg_news().GetModelList("ChannelID=0 and ClassID=" + classid);
            if (slide.Count > 0)
            {
                ;
                for (int i = 0; i < slide.Count; i++)
                {
                    if (i >= 2)
                    { break; }
                    SlideText.AppendFormat("<li ><a href=\"newsdetails.aspx?fid={1}&id={2}&typeid={4}\" title=\"{0}\">{3}</a></li>", slide[i].Name, slide[i].ChannelID, slide[i].ID, kim.Common.Utils.CutString(slide[i].Name, 30), slide[i].ClassID);

                }

            }
            return SlideText;
        }
        public static string  GetTopProductClass()
        {
            string Typeid = string.Empty;
            IList<Model.CClass> CClassList = new BLL.CClass().GetTopCClass(1, "", "Orders Desc,id asc");
            if (CClassList.Count > 0) Typeid = CClassList[0].ID.ToString();
            return Typeid;

        }

        protected string GetPrClass()
        {
            string ClassText = string.Empty;

            DataTable dt = new BLL.CClass().GetList(0, 1);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                    ClassText += "<li><a href=\"products.aspx?typeid=" + dt.Rows[i]["id"] + "\" >" + dt.Rows[i]["ClassName"] + "</a></li>";
               
            }
            return ClassText;

        }

        
        private void GetClass()
        {
            ClassText = new string[11];
            ClassText[0] = "class=\"first\"";
            ClassText[9] = "class=\"last\"";
            fid = KIMRequest.GetInt("fid", 0);
            int typeid = KIMRequest.GetInt("typeid", 0);
            switch (fid)
            {
                case 1:
                    ClassText[1] = "class=\"current\"";
                    break;
                case 2:
                    ClassText[2] = "class=\"current\"";
                    break;
                case 3:
                    ClassText[3] = "class=\"current\"";
                    break;
                case 4:
                    ClassText[4] = "class=\"current\"";
                    break;
                case 5:
                    ClassText[5] = "class=\"current\"";
                    break;
                case 6:
                    ClassText[6] = "class=\"current\"";
                    break;
                case 7:
                    ClassText[7] = "class=\"current\"";
                    break;
                case 8:
                    ClassText[8] = "class=\"current\"";
                    break;
                case 9:
                    ClassText[9] = "class=\"current last\"";
                    break;
            }
            string StrUrl = Request.RawUrl.ToLower(); ;

            if (StrUrl.IndexOf("index") > -1)
            {
                ClassText[0] = "class=\"current\"";
            }

            if (StrUrl.IndexOf("adult") > -1)
            {
                ClassText[4] = "class=\"current\"";
            }
            if (StrUrl.IndexOf("selfstudy") > -1)
            {
                ClassText[5] = "class=\"current\"";
            }
            if (StrUrl.IndexOf("postgraduate") > -1)
            {
                ClassText[6] = "class=\"current\"";
            }
            if (StrUrl.IndexOf("education") > -1)
            {
               
                ClassText[3] = "class=\"current\"";
               
            }
            if (StrUrl.IndexOf("educationdetails") > -1)
            {
                string strUrl1 = HttpContext.Current.Request.UrlReferrer.ToString().ToLower();
                if (strUrl1.IndexOf("adult") > -1)
                {
                    ClassText[4] = "class=\"current\"";
                    ClassText[3] = "";
                }
                if (strUrl1.IndexOf("selfstudy") > -1)
                {
                    ClassText[5] = "class=\"current\"";
                    ClassText[3] = "";
                }
                if (strUrl1.IndexOf("postgraduate") > -1)
                {
                    ClassText[6] = "class=\"current\"";
                    ClassText[3] = "";
                }
            }
            
        }
    }
}